﻿using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.database;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERP_RORZE_PRODUCT.Product.DAO
{
    public class ClsXLBM : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();

        //bảng mẻ mạ
        public DataTable GetAllMeMa()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsMeMa.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertMeMa(string some, int number)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@some", SqlDbType.NVarChar, some),
                    CreateParameter("@Number", SqlDbType.Int, number)
                    
                };
            Execute.DoDelete(clsConstBasicListFuction.ClsXLBMFuction.ClsMeMa.Insert, parameter, true);
        }

        public void UpdateMeMa(string some, string somecu, int number)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@some", SqlDbType.NVarChar, some),
                    CreateParameter("@Number", SqlDbType.Int, number),
                    CreateParameter("@somecu", SqlDbType.NVarChar, somecu)
                    
                };
            Execute.DoDelete(clsConstBasicListFuction.ClsXLBMFuction.ClsMeMa.Update, parameter, true);
        }

        public void DeleteMeMa(string some)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@some", SqlDbType.NVarChar, some)
                    
                };
            Execute.DoDelete(clsConstBasicListFuction.ClsXLBMFuction.ClsMeMa.Delete, parameter, true);
        }

        //bảng dataANO

        public DataTable GetAllDataANO()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllDataANOByID()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetAllByID;
            return Execute.DoStoreProcedure(sql, true);
        }

        public int InsertDataANO(DulieuANO b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.AnoNo, SqlDbType.NVarChar, b.AnoNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.AnoQuan, SqlDbType.NVarChar, b.AnoQuan),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Chieu_day_mang, SqlDbType.Decimal, b.Chieu_day_mang),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Code, SqlDbType.NVarChar, b.Code),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong, SqlDbType.Decimal, b.Maibong),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong_Temp, SqlDbType.Decimal, b.Maibong_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong_Times, SqlDbType.Decimal, b.Maibong_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.MoQuan, SqlDbType.Int, b.MoQuan),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.OrderNo, SqlDbType.NVarChar, b.OrderNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.P_sinh, SqlDbType.NVarChar, b.P_sinh),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.PartNo, SqlDbType.NVarChar, b.PartNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Phuong_phap, SqlDbType.NVarChar, b.Phuong_phap),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Sltreo, SqlDbType.Int, b.Sltreo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_NaOH, SqlDbType.Decimal, b.Tank3_NaOH),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_Temp, SqlDbType.Decimal, b.Tank3_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_Times, SqlDbType.Decimal, b.Tank3_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_H2SO4, SqlDbType.Decimal, b.Tank8_H2SO4),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_Temp, SqlDbType.Decimal, b.Tank8_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_Times, SqlDbType.Decimal, b.Tank8_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Times, SqlDbType.Int, b.Times)
                };
           return Execute.DoDelete2(clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.Insert, parameter, true);
        }

        public int UpdateDataANO(DulieuANO b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.AnoNo, SqlDbType.NVarChar, b.AnoNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.AnoQuan, SqlDbType.NVarChar, b.AnoQuan),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Chieu_day_mang, SqlDbType.Decimal, b.Chieu_day_mang),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Code, SqlDbType.NVarChar, b.Code),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong, SqlDbType.Decimal, b.Maibong),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong_Temp, SqlDbType.Decimal, b.Maibong_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Maibong_Times, SqlDbType.Decimal, b.Maibong_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.MoQuan, SqlDbType.Int, b.MoQuan),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.OrderNo, SqlDbType.NVarChar, b.OrderNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.P_sinh, SqlDbType.NVarChar, b.P_sinh),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.PartNo, SqlDbType.NVarChar, b.PartNo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Phuong_phap, SqlDbType.NVarChar, b.Phuong_phap),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Sltreo, SqlDbType.Int, b.Sltreo),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_NaOH, SqlDbType.Decimal, b.Tank3_NaOH),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_Temp, SqlDbType.Decimal, b.Tank3_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank3_Times, SqlDbType.Decimal, b.Tank3_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_H2SO4, SqlDbType.Decimal, b.Tank8_H2SO4),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_Temp, SqlDbType.Decimal, b.Tank8_Temp),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Tank8_Times, SqlDbType.Decimal, b.Tank8_Times),
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.Times, SqlDbType.Int, b.Times)                   
                };
            return Execute.DoDelete2(clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.Update, parameter, true);
        }

        public void DeleteDataANO(DulieuANO b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.ID, SqlDbType.Int, b.ID)                  
                };
            Execute.DoDelete(clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.Delete, parameter, true);
        }

        public DataTable GetAllByID(DulieuANO b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDulieuANOSP.ID, SqlDbType.Int, b.ID)                  
                };
            return Execute.DoStoreGetByID(clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetAllByID, parameter, true);
        }

        //lấy dữ liệu để in lên form
        public DataTable GetMONo()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetAllMONoAnoData;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetByMONo( string MONo)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@MONo", SqlDbType.NVarChar, MONo)
                    
                };
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetAllMONoAnoData1;
            return Execute.DoStoreGetByID(sql,parameter, true);
        }
        public DataTable GetDulieuslMa()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.getDulieuslMa;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetPartID(string BOrder)
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.GetPartID;
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@BOderNo", SqlDbType.NVarChar, BOrder)
                    
                };
            return Execute.DoStoreGetByID(sql, parameter, true);
        }

        //Kế hoạch hàng ngày
        public DataTable GetKHHN(string Macv, int Songay)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Macv", SqlDbType.NVarChar, Macv),
                    CreateParameter("@Songay", SqlDbType.Int, Songay)
                };
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.KHHN;
            return Execute.DoStoreGetByID(sql,parameter, true);
        }

        //Kế hoạch tổng

        public DataTable GetKHT()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.KHT;
            return Execute.DoStoreProcedure(sql, true);
        }

        // Hàng tồn
        public DataTable GetHT()
        {
            string sql = clsConstBasicListFuction.ClsXLBMFuction.ClsAnoData.HT;
            return Execute.DoStoreProcedure(sql, true);
        }
    }
}
